import 'package:fish_redux/fish_redux.dart';
import 'package:kunlun_gas/app_files.dart';

import 'action.dart';
import 'state.dart';

Effect<FixHistoryViewState> buildEffect() {
  return combineEffects(<Object, Effect<FixHistoryViewState>>{
    // FixHistoryViewAction.action: _onAction,
    Lifecycle.initState: _initState,
  });
}

void _initState(Action action, Context<FixHistoryViewState> ctx) async {
  ResultData res = await CommonNetWork.fixOrderHistoryList(userNo: ctx.state.userNo);
  if (res.success) {
    List list = res.data['data'];
    ctx.state.items = list.map((e) => FixListItemModel.fromJson(e)).toList();
    ctx.dispatch(FixHistoryViewActionCreator.onAction());
  }
  else {
    CommonUtils.showErrorInfo(ctx.context, res.desc);
    ctx.state.items = [];
    ctx.dispatch(FixHistoryViewActionCreator.onAction());
  }
}
